<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
	<link rel="stylesheet" href="../style/ucs.css">
	<link rel="stylesheet" href="../style/theme.css">
</head>
<body>
<div id="giraffe"></div>
<script type="text/javascript" src="../../dist/libs/u-eventhub.js"></script>
<script type="text/javascript" src="../../dist/libs/engine.js"></script>
<script type="text/javascript" src="../../dist/ucsmy-ui.js"></script>
<script>
	//链接
	var URLDM = new UDM({
		home:"../Index/index.html"
	});

	//项目列表模型
	var projectListDM = new UDM({
		value: []
	});

	//分页条模型
	var paginationDM = new UDM({
		value: {	//默认值为0
			totalPage: 0,	//总页数
			pageSize: 3,	//每页显示条数
			curPage: 1	//当前页码
		},
		onClick:function(){
			ajaxFn();
		}
	});

	//年化利率模型
	var interestDM = new UDM({
		option: [
			{
				value: 0,
				text: "全部"
			},
			{
				value :1,
				text: "4%以下"
			},
			{
				value :2,
				text: "4%~5%"
			},
			{
				value :3,
				text: "5%~6%"
			},
			{
				value :4,
				text: "6%以上"
			}
		],
		onClick: function(){
			ajaxFn();
		}
	});

	//投资期限模型
	var durationDM = new UDM({
		option: [
			{
				value: 0,
				text: "全部"
			},
			{
				value :1,
				text: "90天以内"
			},
			{
				value :2,
				text: "90天~180天"
			},
			{
				value :3,
				text: "180天~360天"
			},
			{
				value :4,
				text: "360天以上"
			}
		],
		onClick: function(){
			ajaxFn();
		}
	});

	//项目状态模型
	var projectStatusDM = new UDM({
		option: [
			{
				value: 0,
				text: "全部"
			},
			{
				value :1,
				text: "预热中"
			},
			{
				value :2,
				text: "投标中"
			},
			{
				value :3,
				text: "已满标"
			},
			{
				value :4,
				text: "计息中"
			},
			{
				value :5,
				text: "已还款"
			}
		],
		onClick: function(){
			ajaxFn();
		}
	});

	//收益计算公式 365天
	var daysDM = new UDM({
		value:365
	});

	//模拟后台返回数据
	var listValue = [
		{
			login:true,
			minFlag:true,
			loginUrl:"",
			confirmUrl:"../ProDetail/index.html",
			FinancingId:"bc964a42-34a2-41ff-88eb-91ece2540811",
			ProjectUrl:"http://ttmy.ucsmy.com/Home/Detail?FinancingId=c162bf4a-51f2-487f-90f7-012aa0367f7e&timestamp=1490846882960",
			ProjectName: "商票理财【20160002】",	//项目名称
			Interest: "6.30",	//年化利率（%）
			Duration: 360,	//项目期限（天）
			TotalAmount: 13000,	//项目规模（百万）
			Progress: 10,	//投标进度(%)
			ProjectStatus:2,     //项目状态
			IsExclusive: "1",	//是否是专属项目
			MinAmount: "1000",
			ProjectBeginTime:new Date(new Date().getTime() + 10000),
			JMBeginTime:"2017-06-06",
			Aflag_Icon:"icon_xs.png|只有新用户才能投标,icon_qt.png,icon_jj.png"//活动标识
		},
		{
			login:true,
			minFlag:true,
			loginUrl:"",
			confirmUrl:"../ProDetail/index.html",
			FinancingId:"bc964a42-34a2-41ff-88eb-91ece2540811",
			ProjectUrl:"http://ttmy.ucsmy.com/Home/Detail?FinancingId=c162bf4a-51f2-487f-90f7-012aa0367f7e&timestamp=1490846882960",
			ProjectName: "商票理财【20160002】",	//项目名称
			Interest: "6.30",	//年化利率（%）
			Duration: 360,	//项目期限（天）
			TotalAmount: 1300,	//项目规模（百万）
			Progress: 10,	//投标进度(%)
			ProjectStatus:1,     //项目状态
			IsExclusive: "1",	//是否是专属项目
			MinAmount: "1000",
			ProjectBeginTime:"2017-08-11 17:25:26",
			JMBeginTime:new Date(new Date().getTime() + 10000),
			Aflag_Icon:null
		},
		{
			login:true,
			minFlag:true,
			loginUrl:"",
			confirmUrl:"../ProDetail/index.html",
			FinancingId:"bc964a42-34a2-41ff-88eb-91ece2540811",
			ProjectUrl:"http://ttmy.ucsmy.com/Home/Detail?FinancingId=c162bf4a-51f2-487f-90f7-012aa0367f7e&timestamp=1490846882960",
			ProjectName: "商票理财【20160002】",	//项目名称
			Interest: "6.30",	//年化利率（%）
			Duration: 360,	//项目期限（天）
			TotalAmount: 9999,	//项目规模（百万）
			Progress: 10,	//投标进度(%)
			ProjectStatus:3,     //项目状态
			IsExclusive: "1",	//是否是专属项目
			MinAmount: "1000",
			ProjectBeginTime:"2017-08-11 17:25:26",
			JMBeginTime:"2017-08-25 17:25:26",
			Aflag_Icon:null
		},
		{
			login:true,
			minFlag:true,
			loginUrl:"",
			confirmUrl:"../ProDetail/index.html",
			FinancingId:"bc964a42-34a2-41ff-88eb-91ece2540811",
			ProjectUrl:"http://ttmy.ucsmy.com/Home/Detail?FinancingId=c162bf4a-51f2-487f-90f7-012aa0367f7e&timestamp=1490846882960",
			ProjectName: "商票理财【20160002】",	//项目名称
			Interest: "6.30",	//年化利率（%）
			Duration: 360,	//项目期限（天）
			TotalAmount: 1300,	//项目规模（百万）
			Progress: 10,	//投标进度(%)
			ProjectStatus:4,     //项目状态
			IsExclusive: "1",	//是否是专属项目
			MinAmount: "1000",
			ProjectBeginTime:"2017-08-11 17:25:26",
			JMBeginTime:"2017-08-25 17:25:26"
		},
		{
			login:true,
			minFlag:true,
			loginUrl:"",
			confirmUrl:"../ProDetail/index.html",
			FinancingId:"bc964a42-34a2-41ff-88eb-91ece2540811",
			ProjectUrl:"http://ttmy.ucsmy.com/Home/Detail?FinancingId=c162bf4a-51f2-487f-90f7-012aa0367f7e&timestamp=1490846882960",
			ProjectName: "商票理财【20160002】",	//项目名称
			Interest: "6.30",	//年化利率（%）
			Duration: 360,	//项目期限（天）
			TotalAmount: 1300,	//项目规模（百万）
			Progress: 10,	//投标进度(%)
			ProjectStatus:5,     //项目状态
			IsExclusive: "1",	//是否是专属项目
			MinAmount: "1000",
			ProjectBeginTime:"2017-08-11 17:25:26",
			JMBeginTime:"2017-08-25 17:25:26"
		},
		{
			login:true,
			minFlag:true,
			loginUrl:"",
			confirmUrl:"../ProDetail/index.html",
			FinancingId:"bc964a42-34a2-41ff-88eb-91ece2540811",
			ProjectUrl:"http://ttmy.ucsmy.com/Home/Detail?FinancingId=c162bf4a-51f2-487f-90f7-012aa0367f7e&timestamp=1490846882960",
			ProjectName: "商票理财【20160002】",	//项目名称
			Interest: "6.30",	//年化利率（%）
			Duration: 360,	//项目期限（天）
			TotalAmount: 1300,	//项目规模（百万）
			Progress: 10,	//投标进度(%)
			ProjectStatus:5,     //项目状态
			IsExclusive: "1",	//是否是专属项目
			MinAmount: "1000",
			ProjectBeginTime:"2017-08-11 17:25:26",
			JMBeginTime:"2017-08-25 17:25:26"
		}
	];

	var ajaxFn = function(){
		var interest = interestDM.getValue();	//获取当前选中的年化利率
		var duration = durationDM.getValue();	//获取当前选中的投资期限
		var projectStatus = projectStatusDM.getValue();	//获取当前的项目状态

		var pageSize = paginationDM.getValue().pageSize;	//获取每页显示条数
		var curPage = paginationDM.getValue().curPage;		//获取当前选中页码

		console.log("interest:"+interest+"---duration:"+duration+"---projectStatus:"+projectStatus);
		console.log("pageSize:"+pageSize+"---curPage:"+curPage);

		var ProjectList = [
			{
				ProjectName: "商票理财【20160002】",	//项目名称
				Interest: "6.30",	//年化利率（%）
				Duration: "360",	//项目期限（天）
				TotalAmount: "1300.00",	//项目规模（百万）
				Progress: 30,	//投标进度(%)
				ProjectStatus: "1",	//投标状态
				IsExclusive: "1"	//是否是专属项目
			},
			{
				ProjectName: "商票理财【20160002】",	//项目名称
				Interest: "6.30",	//年化利率（%）
				Duration: "360",	//项目期限（天）
				TotalAmount: "1300.00",	//项目规模（百万）
				Progress: 10,	//投标进度(%)
				ProjectStatus: "1",	//投标状态
				IsExclusive: "1"	//是否是专属项目
			}
		];
		var Rule = {
			Interest:{threshold:10},	//正常为黑色，大于等于threshold加红加粗
			IsExclusive:{flag:1},	//如果为1则显示标志，为0则不显示
			Duration:{threshold:360},	//正常为黑色,大于等于365显示绿色
			Progress:{threshold:90},	//正常为黑色,大于等于90显示绿色
			ProjectStatus:[{value:'1',name:'投标中'}],	//“投标中”蓝色，“预热中”红色，“已满标”灰色
			SurplusTimeWarmUp:{threshold:7},	//正常为黑色,小于等于7显示红色
			SurplusTimeTending:{threshold:7}	//正常为黑色,小于等于7显示红色
		};
		var MixRule = {
			SuperStar:{
				Interest:{threshold:10},
				Progress:{min:90,max:99}
			}
		};

		var curListValue = [];

		var paginationValue = {
			totalPage: Math.ceil(listValue.length/pageSize),	//总页数
			pageSize: pageSize,	//每页显示条数
			curPage: curPage	//当前页码
		}
		if(listValue.length>0){
			for(var i = curPage*pageSize - pageSize ; i < curPage*pageSize ; i ++){
				curListValue.push(listValue[i]);
			}
		}

		projectListDM.setValue(curListValue);
		paginationDM.setValue(paginationValue);
	};

	var PageDM = {
		URL:URLDM,
		projectList: projectListDM,
		pagination: paginationDM,
		interest: interestDM,
		duration: durationDM,
		projectStatus: projectStatusDM,
		days:daysDM
	}

	UEventHub.on('pageLoad', function(v){
		ajaxFn();
		console.log(v);
		UEventHub.emit("test","你好，","世界！");
	});

	UEventHub.on('test', function(v,d){
		console.log(v+d);
	});

</script>
</body>
</html>
